m=10
T=[None]*m #Hash table

def h(k,i): #Hash function
    return (k%3+i)%m
def hash_insert(T,k):
    for i in range(m):
        j=h(k,i)
        if T[j]==None or T[j]=='Deleted':
            T[j]=k
            return j
    raise Exception('Hash table overflow')
def hash_search(T,k):
    for i in range(m):
        j=h(k,i)
        if T[j]==k:
            return j
    return 'Not found'
def hash_delete(T,k):
    idx=hash_search(T,k)
    if idx=='Not found':
        raise Exception('No such element')
    T[idx]='Deleted'
    
if __name__=='__main__':
    for i in range(8):
        hash_insert(T,i*3)
    print T
    print '18 at:', hash_search(T,18)
    print '7 at:', hash_search(T,7)
    hash_delete(T,12)
    print T
    hash_insert(T,24)
    print T
    
